/*
 * Hibiscus is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 3 of the License,
 * or (at your option) any later version.
 *
 * Hibiscus is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Hibiscus; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 *
 * Copyright (C) 2003 Tetete - http://tetete.hu.
 */
package hu.tetete.hibiscus.propertyvalue;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import hu.tetete.hibiscus.model.MultiSelectProperty;


/**
 * Contains the selected values for a {@link MultiSelectProperty}.
 */
public class MultiSelectPropertyValue extends PropertyValue {

    /** @see Serializable */
    private static final long serialVersionUID = 1L;

    private final Set<SelectPropertyValue> values;

    /**
     * @param values The selected values to set
     */
    public MultiSelectPropertyValue(final Set<SelectPropertyValue> values) {
        this.values = values;
    }


    /**
     * @param value One selected value to set
     */
    public MultiSelectPropertyValue(final SelectPropertyValue value) {
        this.values = new HashSet<SelectPropertyValue>();
        this.values.add(value);
    }


    /**
     * @return the values
     */
    public Set<SelectPropertyValue> getValues() {
        return this.values;
    }

    /**
     * Removes a selected element.
     * @param value The element to remove
     * @return <tt>true</tt> if the element was part of the selection, <tt>false</tt> otherwise
     */
    public boolean deleteElement(final SelectPropertyValue value) {
        return this.values.remove(value);
    }

    /**
     * Adds an element to the selection.
     * @param value The new element
     */
    public void addElement(final SelectPropertyValue value) {
        this.values.add(value);
    }

    /**
     * Checks the value if the value is selected.
     * @param selectPropertyValue The value to check if is selected.
     * @return <tt>true</tt> if the value is selected.
     */
    public boolean contains(final SelectPropertyValue selectPropertyValue) {
        return this.values.contains(selectPropertyValue);
    }

}
